#ifndef __SOFTSPI_H__
#define __SOFTSPI_H__
#include "BasicInterface.h"
#include "stm32f10x.h"

//#define IO_OBJECT

#define IO_BITBAND



#ifdef USE_BASICIO
class SoftSPI:public BasicIO
#pragma push
#pragma diag_suppress 1300
#else
class SoftSPI
#endif
{
	private:
#if (defined IO_OBJECT)
		const GPIO::Bit MOSI,MISO,CS,SCLK;
#elif (defined IO_BITBAND)
		volatile uint32_t *MOSI,*MISO,*CS,*SCLK;
#endif
	protected:

	public:
		SoftSPI(const GPIO::Bit &_MOSI,const GPIO::Bit &_MISO,const GPIO::Bit &_CS,const GPIO::Bit &_SCLK)
		{
			MOSI = _MOSI.GetO();
			MISO = _MISO.GetI();
			SCLK = _SCLK.GetO();
			CS = _CS.GetO();
			*CS = 1;
		}
		SoftSPI(const SoftSPI& Other):MOSI(Other.MOSI),MISO(Other.MISO),CS(Other.CS),SCLK(Other.SCLK) {}
		uint8_t RWByte(uint8_t Byte) const;
		void SetCS(bool Sta) const
		{
			*CS = Sta;
		}
#ifdef USE_BASICIO
		virtual Resault Read(const uint32_t address,void* buffer,uint32_t length) const;
		virtual Resault Write(const uint32_t address,const void* buffer,uint32_t length) const;
		virtual const BasicIO& operator >> (uint32_t& Data) const;
		virtual const BasicIO& operator << (const uint32_t Data) const;
#pragma pop
#endif
};


#endif
